import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
Vue.use(VueRouter)

// 增强push方法
   //保存方法
   let originPush = VueRouter.prototype.push
   VueRouter.prototype.push = function origin(location,okCallback,errCallback){
     if(okCallback || errCallback){
       return originPush.call(this,location,okCallback,errCallback)
     }else{
       return originPush.call(this,location).catch(()=>{})
     }
   }
 
export default new VueRouter({
    mode:'history',
    routes,
    scrollBehavior(to,from,savePosition){
    // scrollBehavior函数：每次路由跳转时都会执行
  	// to:要跳到哪个路由
  	// from:来自于哪个路由
  	// savedPosition:跳转前滚动条的位置
    if(savePosition){
    //只有进行前进后退时savedPosition才有值,正常跳转，值为null
    return savePosition
    }else{
        return {x:0,y:0}
    }
    }
})